package com.ymatou.iapi.m.couponservice.testcase;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.m.couponservice.parameter.GetSellerBatchCountInCurrentMonthBean;
import com.ymatou.iapi.m.couponservice.parameter.SellerCreateBatchBean;
import com.ymatou.iapi.m.couponservice.service.GetSellerBatchCountInCurrentMonthCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponServiceMCallService;
import com.ymttest.database.sqlwapper.YmtCouponBatchWapper;
import com.ymttest.utils.EnvSetup;
/**
*获取商家当月优惠券数量信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetSellerBatchCountInCurrentMonth{
	private static GetSellerBatchCountInCurrentMonthBean getsellerbatchcountincurrentmonthBean;
	private static GetSellerBatchCountInCurrentMonthCall getsellerbatchcountincurrentmonthCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取商家当月优惠券数量信息");
	}

	@Before
	public void caseUp() {
		getsellerbatchcountincurrentmonthBean=new GetSellerBatchCountInCurrentMonthBean();
		getsellerbatchcountincurrentmonthCall=new GetSellerBatchCountInCurrentMonthCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getsellerbatchcountincurrentmonthCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_GetSellerBatchCountInCurrentMonth_001() {
		Logger.start(true,"获取商家当月优惠券数量信息-验证总数");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			getsellerbatchcountincurrentmonthBean.setSellerId(sellerId);
			
			getsellerbatchcountincurrentmonthCall.setData(getsellerbatchcountincurrentmonthBean);
			getsellerbatchcountincurrentmonthCall.callService();			
			
			Logger.verifyEquals("0", getsellerbatchcountincurrentmonthCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getsellerbatchcountincurrentmonthCall.getMessage(), "验证返回Message");
				
			// 获取当月第一天和最后一天  
	        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");  
	        String firstday, lastday;  
	        // 获取前月的第一天  
	        Calendar cale = Calendar.getInstance();  
	        cale.add(Calendar.MONTH, 0);  
	        cale.set(Calendar.DAY_OF_MONTH, 1);  
	        firstday = format.format(cale.getTime());  
	        // 获取前月的最后一天  
	        cale = Calendar.getInstance();  
	        cale.add(Calendar.MONTH, 1);  
	        cale.set(Calendar.DAY_OF_MONTH, 0);  
	        lastday = format.format(cale.getTime()); 
			
			int count = new YmtCouponBatchWapper().getSellerBatchCountInCurrentMonth(sellerId, format.parse(firstday), format.parse(lastday));
			Logger.verifyEquals(count, Integer.parseInt(getsellerbatchcountincurrentmonthCall.getCount()), "验证返回Count");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerBatchCountInCurrentMonth_002() {
		Logger.start(true,"获取商家当月优惠券数量信息-sellerid空");
		try {
			
			getsellerbatchcountincurrentmonthCall.setData(getsellerbatchcountincurrentmonthBean);
			getsellerbatchcountincurrentmonthCall.callService();			
			
			Logger.verifyEquals("0", getsellerbatchcountincurrentmonthCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getsellerbatchcountincurrentmonthCall.getMessage(), "验证返回Message");
			
			Logger.verifyEquals(0, Integer.parseInt(getsellerbatchcountincurrentmonthCall.getCount()), "验证返回Count");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerBatchCountInCurrentMonth_003() {
		Logger.start(true,"获取商家当月优惠券数量信息-验证新建的返回正确");
		try {
			CouponServiceMCallService couponServiceMCallService = new CouponServiceMCallService();
			SellerCreateBatchBean sellercreatebatchBean = couponServiceMCallService.setDefaultSellerCreateBatchBean();
			couponServiceMCallService.SellerCreateBatch(sellercreatebatchBean);
			couponServiceMCallService.SellerCreateBatch(sellercreatebatchBean);
			couponServiceMCallService.SellerCreateBatch(sellercreatebatchBean);

			getsellerbatchcountincurrentmonthBean.setSellerId(sellercreatebatchBean.getSellerId());
			
			getsellerbatchcountincurrentmonthCall.setData(getsellerbatchcountincurrentmonthBean);
			getsellerbatchcountincurrentmonthCall.callService();			
			
			Logger.verifyEquals("0", getsellerbatchcountincurrentmonthCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getsellerbatchcountincurrentmonthCall.getMessage(), "验证返回Message");
				
			Logger.verifyEquals(3, Integer.parseInt(getsellerbatchcountincurrentmonthCall.getCount()), "验证返回Count");  
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}